#include "CallBack.h"
#include "FUNCTIONS.h"


int sln_ntf_cid_blj(PSLN_NETLINK msg) {

	//test主动
	char new_cid1[64] = "0403";
	char new_rid1[64] = "0403";
	char new_mac1[64] = "0403";
	char new_ifi1[64] = "ens1";
	//sln_add_cid(0, new_cid1, new_rid1, new_mac1, new_ifi1);


	PSLN_CID	msg_table = (PSLN_CID)(msg->body);
	int			id		  =	msg->pktid;


	//test被动
	char new_cid2[64] = "0111";
	char new_rid2[64] = "0111";
	char new_mac2[64] = "0111";
	char new_ifi2[64] = "ens2";
	//sln_add_cid(id, new_cid2, new_rid2, new_mac2, new_ifi2);

	
	char cid_str[64];
	char jsonData[1024];

    Functions::sln_bin2str(cid_str, msg_table->cid, 16);

	//组装post请求,查询路由标识等信息
	char url[] = "http://127.0.0.1:40123";
    snprintf(jsonData, sizeof(jsonData), "{\"cid\": \"%s\"}", cid_str);
	printf("JSON : [%s]\n", jsonData);

	Json::Value response = Functions::send_post_request(url, jsonData);
	//测试输出：
	std::cout << "回调函数已发送POST请求查询数据:" << std::endl << jsonData << std::endl << "rsponse:" << response["rid"].asString() << response["mac"].asString() << response["ifn"].asString();
	std::string rid = response["rid"].asString();
	std::string mac = response["mac"].asString();
	std::string	ifn = response["ifn"].asString();



	//add回表中
	char* new_rid = (char*)rid.c_str();

	char new_cid[64];
	Functions::sln_bin2str(new_cid, msg_table->cid, 16);

	char* new_mac = (char*)mac.c_str();	
	

	const char* new_ifn = ifn.c_str();

	if(rid != "" && mac != "" && ifn != "")
		//sln_add_cid(id, new_cid, new_rid, new_mac, (char*)new_ifn);
	return 0;
}



extern "C" {
	int sln_ntf_cid_blj(PSLN_NETLINK	msg);
}

